from awesum import *
from ball import Ball
from block import Block
from paddle import Paddle

class SceneLevel(Scene):
	def __init__(self):
		super(SceneLevel, self).__init__()
		self.ball = None
		self.paddles = []
	
	def load(self, game):
		self.textures.loadTex("red.bmp", Texture.Type.SQUARE)
		self.textures.loadTex("16.bmp", Texture.Type.GRID, [4, 4])
		
		game.cam.set(Vector3(5, 3, 12), Vector3(5, 2, -5), Vector3(0, 1, 0))
		#game.cam.set(Vector3(-12, 3, 0), Vector3(0, 2, -5), Vector3(0, 1, 0))
		
		l1 = game.loadLevel("l1.json")
		for ball in l1["ball"]:
			self.drawables.append(Ball(Vector3(ball["pos"][0], ball["pos"][1], ball["pos"][2])))
			#break
		for block in l1["block"]:
			if block["type"] == "b":		type = Block.Type.BOOST
			elif block["type"] == "sb":	type = Block.Type.SUPERBOOST
			elif block["type"] == "r":		type = Block.Type.REDUCE
			elif block["type"] == "br":	type = Block.Type.BREAK
			elif block["type"] == "s":		type = Block.Type.SLIDE
			else:							type = Block.Type.NORMAL
			self.drawables.append(Block(Vector3(block["pos"][0], block["pos"][1], block["pos"][2]), type))
		
		for block in l1["paddle"]:
			p = Paddle(Vector3(block["pos"][0], block["pos"][1], block["pos"][2]), type)
			self.drawables.append(p)
			self.paddles.append(p)
		
		super(SceneLevel, self).load(game)
		self.drawables[-2].gl.scaleV(Vector3(1, 2, 1))
	
	def step(self):
		super(SceneLevel, self).step()
		
		keys = self.game.keys
		
		#D-pad left/right, keyboard left/right - turn car
		if (Key.LEFT in keys or self.game.gamepad.left or self.game.gamepad.b5):
			for p in self.paddles:
				p.moveLeft()
		elif (Key.RIGHT in keys or self.game.gamepad.right or self.game.gamepad.b7):
			for p in self.paddles:
				p.moveRight()
		else:
			pass